package com.william.lifetraxer.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbOpenHelper extends SQLiteOpenHelper{
	
	public DbOpenHelper(Context context){
		super(context, Database.DATABASE_NAME , null, Database.DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		
		db.execSQL("CREATE TABLE " + UserDb.TABLE_NAME + " ("
                + UserDb.UserColumns._ID + " INTEGER PRIMARY KEY,"
                + UserDb.UserColumns.USERNAME+ " TEXT,"
                + UserDb.UserColumns.USER_ID + " INTEGER,"
                + UserDb.UserColumns.NEW_TRACK_ID + " INTEGER,"
                + UserDb.UserColumns.PHOTO_PATH + " TEXT"
                + ");");
		
		db.execSQL("CREATE TABLE " + TrackDb.TABLE_NAME + " ("
				+ TrackDb.TrackColumns._ID + " INTEGER PRIMARY KEY,"
				+ TrackDb.TrackColumns.TRACK_ID + " INTEGER,"
				+ TrackDb.TrackColumns.USER_ID + " INTEGER,"
				+ TrackDb.TrackColumns.GROUP_ID + " INTEGER,"
				+ TrackDb.TrackColumns.PATH + " TEXT,"
				+ TrackDb.TrackColumns.TYPE + " INTEGER"
				+ TrackDb.TrackColumns.NAME + " TEXT"
				+ ");");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + UserDb.TABLE_NAME );
		db.execSQL("DROP TABLE IF EXISTS " + TrackDb.TABLE_NAME);
        onCreate(db);
	}
	
}
